import { defineStore } from 'pinia'
import { GetAllCategory, UploadFile, CreateInfo, GetInfoList, ChangeInfoStatus, DeleteInfo, GetInfoDetail, UpdateInfo } from '@/api/info'

export const useInfoStore = defineStore('info', () => {
  function getAllCategoryAction(requestData = {}) {
    return new Promise((resolve, reject) => {
      GetAllCategory(requestData).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  }

  function uploadFileAction(requestData = {}) {
    return new Promise((resolve, reject) => {
      UploadFile(requestData).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  }

  function createInfoAction(requestData = {}) {
    return new Promise((resolve, reject) => {
      CreateInfo(requestData).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  }

  function getInfoListAction(requestData = {}) {
    return new Promise((resolve, reject) => {
      GetInfoList(requestData).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  }

  function changeInfoStatusAction(requestData = {}) {
    const { id, data } = requestData
    return new Promise((resolve, reject) => {
      ChangeInfoStatus(id, data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  }

  function deleteInfoAction(requestData = {}) {
    const { id, data } = requestData
    return new Promise((resolve, reject) => {
      DeleteInfo(id, data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  }

  function getInfoDetailAction(id) {
    return new Promise((resolve, reject) => {
      GetInfoDetail(id).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  }

  function updateInfoAction(requestData = {}) {
    const { id, data } = requestData
    return new Promise((resolve, reject) => {
      UpdateInfo(id, data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  }
  return { getAllCategoryAction, uploadFileAction, createInfoAction, getInfoListAction, changeInfoStatusAction, deleteInfoAction, getInfoDetailAction,updateInfoAction }
})